/** 字节流加解密对象 */
const BinaryCrypter = {
    /** 字节流加密 */
    encrypt: (bytes: Uint8Array, offset = 7) => {
        offset % 255 == 0 && offset++
        for (let i = 0, len = bytes.byteLength; i < len; i++) {
            bytes[i] = ~((bytes[i] + offset) % 256)
        }
        return bytes
    },
    /** 字节流解密 */
    decrypt: (bytes: Uint8Array, offset = 7) => {
        offset % 255 == 0 && offset++
        for (let i = 0, len = bytes.byteLength; i < len; i++) {
            bytes[i] = (~bytes[i] - offset) % 256
        }
        return bytes
    }
}

export default BinaryCrypter